"use strict"

const moment = require('moment')

module.exports = app => {
    const { STRING, DATE, INTEGER} = app.Sequelize
    const AttributeValue = app.model.define('attribute_value', {
        id: {
            type: INTEGER,
            autoIncrement: true,
            primaryKey: true,
        },
        attribute_id: {
            type: INTEGER,
            allowNull: false
        },
        value: {
            type: STRING,
            allowNull: false
        },  
        create_time: {
            type: DATE,
            allowNull: false,
            get() {
                return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss')
            }
        },
    }) 

    AttributeValue.associate = function() {
        app.model.AttributeValue.belongsTo(app.model.AttributeKey, { foreignKey: 'attribute_id', targetKey: 'id' });
    };
    return AttributeValue
}